/*
 * Copyright 2010 Christoph Widulle (christoph.widulle@googlemail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */


package com.android1.amarena2d.nodes;

import com.android1.amarena2d.input.FullScreenTouchSpot;
import com.android1.amarena2d.nodes.behavior.Touchable;
import com.android1.amarena2d.nodes.behavior.delegates.DefaultTransformDelegate;
import com.android1.amarena2d.nodes.behavior.delegates.LayerTouchDelegate;
import com.android1.amarena2d.nodes.behavior.delegates.TouchDelegate;
import com.android1.amarena2d.nodes.behavior.delegates.TransformDelegate;

public class LayerNode extends BaseNode<LeafEntity> implements Touchable<FullScreenTouchSpot> {


    @Override
    public TransformDelegate transform() {
        if (transformDelegate == null) {
            transformDelegate = new DefaultTransformDelegate(this);
        }
        return transformDelegate;
    }

    @Override
    public TouchDelegate<FullScreenTouchSpot> touch() {
        if (touchDelegate == null)
            touchDelegate = new LayerTouchDelegate(this);
        return touchDelegate;
    }

    @Override
    public float getWidth() {
        return engine.getCamera().getWidth();
    }

    @Override
    public float getHeight() {
        return engine.getCamera().getHeight();
    }


    @Override
    public boolean onTouchDown(float x, float y, int pointer, boolean isHit) {
        return false;
    }

    @Override
    public boolean onTouchUp(float x, float y, int pointer, boolean isHit) {
        return false;
    }

    @Override
    public boolean onTouchDragged(float x, float y, int pointer, boolean isHit) {
        return false;
    }

    @Override
    public void enter() {
        if (touchDelegate != null)
            touchDelegate.resume();
        super.enter();

    }

    @Override
    public void exit() {
        if (touchDelegate != null)
            touchDelegate.pause();
        super.exit();

    }

    @Override
    public void dispose() {
        if (touchDelegate != null) {
            touchDelegate.revokeTouchable();
            touchDelegate = null;
        }
        super.dispose();
    }


    @Override
    @SuppressWarnings("unchecked")
    public void setParent(NodeEntity parent) {
        if (parent != null && !(parent instanceof LayerNode))
            throw new IllegalArgumentException("Layer can only be child of a scene or another layer.");
        super.setParent(parent);
    }

}
